from game import zz_game
from zz import zz_log, zz_img
import random

log = zz_log.of()


class Game(zz_game.ZZ_Game):
    def __init__(self, d, has_prize=True):
        super().__init__(d, has_prize)

    def get_name(self):
        return "疯狂接化发"

    def game_alert(self):
        self.alert_close_by_file("./game/img/疯狂接化发")

    # def check_done(self):
    #     return False

    def click_random(self):
        w, h = self.d.window_size()
        w10 = int(w * 0.2)
        h10 = int(h * 0.2)
        x = random.randint(w10, w - w10)
        y = random.randint(h10, h / 2)  # 半屏
        self.log_msg(f"随机坐标点击：{x},{y}")
        self.d.click(x, y)
        self.d.sleep(0.5)

    def handle_main(self):
        self.log_msg("等待进入游戏主界面")
        self.img_exit('./game/img/疯狂接化发/play_start.png', 100)
        self.log_msg("已进入游戏主界面")
        self.log_msg("点击开始游戏")
        self.img_click('./game/img/疯狂接化发/play_start.png')
        self.d.sleep(5)

        if self.not_prize_handle():
            return False

        self.game_alert()

        self.log_msg("开始点麻将")
        while not self.check_done():
            for i in range(5):
                self.click_random()

            self.game_alert()

        # self.d.sleep(2)
        #        self.close_game()
        return True
